﻿@model ThaireInvestmentWeb.Models.AddFixedIncomePurchaseModel
@{
    ViewBag.Title = "Add FixedIncomePurchase";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
<script>
    $(document).ready(function () {

        applyValidateDate();
        $("#TradeDate,#SettlementDate").datepicker(
            {
                dateFormat: 'dd/mm/yy',
                showOn: 'button',
                showAnim: 'fadeIn',
                changeMonth: true,
                changeYear: true,
                showButtonPanel: true,
                buttonImage: '@Url.Content("~/Content/images/Calendar.png")'
            });
        
        $("#Unit").change(calALL);
        $("#Purchase_Par").change(calALL);
        $("#CleanPrice").change(calALL);
        $("#AI").change(calALL);
        
        $("#Purchase_ParValue").change(calALL );

        $("#Purchase_ExchRate").change(calALL);
        

        $("#CancelBtn").click(function (event)
        {
            //showConfirm("Are you sure to cancel ?", CancelBtnAction);
            showConfirm(null, CancelBtnAction);
            return false;
        });
        function CancelBtnAction(event)
        {
            
            window.location.href= 'EditFixedIncome?fixedincomeID=@Model.HeaderID';
        }

    });

    function calALL()
    {
       
        calParValue();
        calGrossPrice();



    }

    function calPurchaseValueForeign()
    {
        //alert('xxx ');
       
        var rate = $("#Purchase_ExchRate").val();
        var pValue = $("#Purchase_PurchaseValueTh").val();      
        if (rate != '' && pValue != '') {
            var purchaseValueForeign = parseDouble(rate) * parseDouble(pValue);
            $('#Purchase_PurchaseValueForeign').val(FormatNumber2(purchaseValueForeign));
        }
    }
    function calParValue()
    {
       // alert('xxx ');
        var unit = $("#Unit").val();
        var par = $("#Purchase_Par").val();      
        if (unit != '' && par != '') {
            var payValue = parseDouble(unit) * parseDouble(par);
            $('#Purchase_ParValue').val(FormatNumber5(payValue));
        }
    }
    function calGrossPrice()
    {
    
        var p1 = $("#CleanPrice").val();
        var p2 = $("#AI").val();      
        if (p1 != '' && p2 != '') 
        {
            var payValue = parseDouble(p1) + parseDouble(p2);
            $('#Purchase_GrossPrice').val(FormatNumber5(payValue));
            $('#Purchase_PurchaseValueTh').val(FormatNumber2(payValue));
            calDiscountPremium();
            calPurchaseValueForeign();
        }
    }
    function calDiscountPremium()
    {
    
        var p1 = $("#Purchase_ParValue").val();
        var p2 = $("#CleanPrice").val();      
        if (p1 != '' && p2 != '') {
            var payValue = parseDouble(p1) - parseDouble(p2);
            $('#Purchase_DiscountPremium').val(FormatNumber5(payValue));

        }
    }
    
    
</script>


<p>
    <table class="navi" width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
        <tr>
            <td style="width: 100%;">
                <div class="navi">Instrument Type > <a href="fixedIncomeList">Fixed Income List</a>> <a href="fixedIncome">Header </a>> Purchase </div>
            </td>
        </tr>
    </table>
</p>
<p>
    <table class="tableheader" width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
        <tr>
            <td height="38" align="center" style="width: 100%; text-align: center;">INPUT Purchase Fixed Income Securities</td>
        </tr>
    </table>
    <table width="951" border="0" align="center">
        <tr>
            <td>
                @*<form action="#" method="post" name="frmSrc" id="frmSrc">*@

                <div align="center">
                    @Html.ValidationSummary(true)
                </div>


                <table width="100%" border="0" align="center" cellspacing="2">
                    <tr>
                        <td width="650">&nbsp;</td>
                        <td align="left">
                            <div style="text-align: left">Create by : @Html.DisplayFor(model => model.Header.CreateUserId) </div>
                        </td>
                        <td width="5">&nbsp;</td>
                    </tr>
                    <tr>
                        <td width="650">&nbsp;</td>
                        <td align="left">
                            <div style="text-align: left">Create Time :  @Html.DisplayFor(model => model.Header.CreateTs)</div>
                        </td>
                        <td width="5">&nbsp;</td>
                    </tr>
                    <tr>
                        <td width="650">&nbsp;</td>
                        <td align="left">
                            <div style="text-align: left">Update by : @Html.DisplayFor(model => model.Header.UpdateUserId) </div>
                        </td>
                        <td width="5">&nbsp;</td>
                    </tr>
                    <tr>
                        <td width="650">&nbsp;</td>
                        <td align="left">
                            <div style="text-align: left">Update Time :  @Html.DisplayFor(model => model.Header.UpdateTs)</div>
                        </td>
                        <td width="5">&nbsp;</td>
                    </tr>
                </table>
                @Html.Partial("_FixedIncomeHeaderView", Model)
                <div>&nbsp;</div>

                @using (Html.BeginForm("ExecuteForAddFixedIncomePurchase", "FixedIncome", FormMethod.Post, new { id = "mainForm" }))
                {

                    <table class="tableform" width="100%" border="0" align="center" cellspacing="2">
                        <tr>
                            <td width="212">
                                <div align="right">Transaction : </div>
                            </td>
                            <td width="8">&nbsp;</td>
                            <td width="246">
                                @Html.DropDownListFor(x => x.SelectedTransactionType, Model.TransactionTypeList)
                                @*<select name="select10" id="select17" onclick="return select17_onclick()">
                                    <option value="1">Purchase</option>
                                    <option value="2">Subscription</option>
                                </select>*@
                            </td>
                            <td width="188" align="right">&nbsp;</td>
                            <td width="6">&nbsp;</td>
                            <td width="208">&nbsp;</td>
                        </tr>
                        <tr>
                            <td>
                                <div align="right">Ref. No. <span class="error">*</span> : </div>
                            </td>
                            <td>&nbsp;</td>
                            <td>
                                @Html.TextBoxFor(model => model.RefNo)
                                @Html.ValidationMessageFor(model => model.RefNo)

                            </td>
                            <td>
                                <div align="right">Type of Payment <span class="error">*</span> : </div>
                            </td>
                            <td>&nbsp;</td>
                            <td>
                               
                                @Html.DropDownListFor(x => x.SelectedTypeOfPayment, Model.TypeOfPaymentList)
                                   @Html.ValidationMessageFor(model => model.SelectedTypeOfPayment)
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <div align="right">Time to Maturity Date  : </div>
                            </td>
                            <td>&nbsp;</td>
                            <td>
                                @Html.TextBoxFor(model => model.TIME2MATURE, new { @readonly = "readonly" })
                            </td>
                            <td>&nbsp;</td>
                            <td>&nbsp;</td>
                            <td>&nbsp;</td>
                        </tr>
                        <tr>
                            <td>
                                <div align="right">Trade Date <span class="error">*</span>  : </div>
                            </td>
                            <td>&nbsp;</td>
                            <td>
                                @Html.TextBoxFor(model => model.TradeDate,new {need_validateDate=true,  @Value = ThaireInvestmentWeb.Util.WebUtil.FormatDate(@Model.TradeDate) })
                                (Ex.31/12/2014) @Html.ValidationMessageFor(model => model.TradeDate)
                            </td>
                            <td>
                                <div align="right">Settlement Date <span class="error">*</span> : </div>
                            </td>
                            <td>&nbsp;</td>
                            <td>
                                @Html.TextBoxFor(model => model.SettlementDate, new {need_validateDate=true, @Value = ThaireInvestmentWeb.Util.WebUtil.FormatDate(@Model.SettlementDate) })
                                 (Ex.31/12/2014) @Html.ValidationMessageFor(model => model.SettlementDate)
                            </td> 
                        </tr>
                        <tr>
                            <td>
                                <div align="right">Unit <span class="error">*</span>    : </div>
                            </td>
                            <td>&nbsp;</td>
                            <td>
                                @Html.TextBoxFor(model => model.Unit, new { @class = "inputNumberField" ,@Value = ThaireInvestmentWeb.Util.WebUtil.FormatCurrency0(@Model.Unit) })
                                @Html.ValidationMessageFor(model => model.Unit)

                            </td>
                            <td>
                                &nbsp;
                                @*<div align="right">Total Size  : </div>*@
                            </td>
                            <td>&nbsp;</td>
                            <td>
                                &nbsp;
                               @* @Html.TextBoxFor(model => model.Purchase.TotalSize, new { @class = "inputNumberField"  ,@Value = ThaireInvestmentWeb.Util.WebUtil.FormatCurrency0(@Model.Purchase.TotalSize)  })
                                @Html.ValidationMessageFor(model => model.Purchase.TotalSize)*@
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <div align="right">Par : </div>
                            </td>
                            <td>&nbsp;</td>
                            <td>
                                @Html.TextBoxFor(model => model.Purchase.Par, new { @class = "inputNumberField"  ,@Value = ThaireInvestmentWeb.Util.WebUtil.FormatCurrency5(@Model.Purchase.Par)  })
                                @Html.ValidationMessageFor(model => model.Purchase.Par)
                            </td>
                            <td>
                                <div align="right">Par Value : </div>
                            </td>
                            <td>&nbsp;</td>
                            <td>
                                @Html.TextBoxFor(model => model.Purchase.ParValue, new { @readonly = "readonly", @class = "inputNumberField"  ,@Value = ThaireInvestmentWeb.Util.WebUtil.FormatCurrency5(@Model.Purchase.ParValue)})
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <div align="right">Yield <span class="error">*</span>  : </div>
                            </td>
                            <td>&nbsp;</td>
                            <td>
                                @Html.TextBoxFor(model => model.Yield, new { @class = "inputNumberField" ,@Value = ThaireInvestmentWeb.Util.WebUtil.FormatCurrency5(@Model.Yield)})
                                @Html.ValidationMessageFor(model => model.Yield)
                                &nbsp; % </td>
                            <td>&nbsp;</td>
                            <td>&nbsp;</td>
                            <td>&nbsp;</td>
                        </tr>
                        <tr>
                            <td>
                                <div align="right">Clean Price <span class="error">*</span>  : </div>
                            </td>
                            <td>&nbsp;</td>
                            <td>
                                @Html.TextBoxFor(model => model.CleanPrice, new { @class = "inputNumberField"  ,@Value = ThaireInvestmentWeb.Util.WebUtil.FormatCurrency5(@Model.CleanPrice)})
                                @Html.ValidationMessageFor(model => model.CleanPrice)
                                &nbsp;</td>
                            <td>
                                <div align="right"></div>
                            </td>
                            <td>&nbsp;</td>
                            <td>&nbsp;</td>
                        </tr>
                        <tr>
                            <td>
                                <div align="right">AI <span class="error">*</span>  : </div>
                            </td>
                            <td>&nbsp;</td>
                            <td>
                                @Html.TextBoxFor(model => model.AI, new { @class = "inputNumberField"  ,@Value = ThaireInvestmentWeb.Util.WebUtil.FormatCurrency5(@Model.AI) })
                                @Html.ValidationMessageFor(model => model.AI)
                            </td>
                            <td>&nbsp;</td>
                            <td>&nbsp;</td>
                            <td>&nbsp;</td>
                        </tr>
                        <tr>
                            <td>
                                <div align="right">Gross Price : </div>
                            </td>
                            <td>&nbsp;</td>
                            <td>
                                @Html.TextBoxFor(model => model.Purchase.GrossPrice, new { @readonly = "readonly" ,@class = "inputNumberField"   ,@Value = ThaireInvestmentWeb.Util.WebUtil.FormatCurrency5(@Model.Purchase.GrossPrice)})
                            </td>
                            <td>
                                <div align="right">
                                    <div align="right">Discount / Premium   : </div>
                                </div>
                            </td>
                            <td>&nbsp;</td>
                            <td>
                                @Html.TextBoxFor(model => model.Purchase.DiscountPremium, new { @readonly = "readonly",@class = "inputNumberField"  ,@Value = ThaireInvestmentWeb.Util.WebUtil.FormatCurrency5(@Model.Purchase.DiscountPremium) })
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <div align="right">Physical    : </div>
                            </td>
                            <td>&nbsp;</td>
                            <td>
                                @*<select name="select12" id="select18">
                                    <option>--Select data--</option>
                                    <option value="1">scrip</option>
                                    <option value="2">scripless</option>
                                    <option value="3">3</option>
                                </select>*@
                                @Html.DropDownListFor(x => x.SelectedPhysical, Model.PhysicalList)
                            </td>
                            <td>
                                <div align="right">Keep at : </div>
                            </td>
                            <td>&nbsp;</td>
                            <td>
                                @* <select name="select14" id="select13">
                                    <option>--Select data--</option>
                                    <option value="1">Custodian</option>
                                    <option value="2">OIC</option>
                                    <option value="3">Safe</option>
                                </select>*@
                                @Html.DropDownListFor(x => x.SelectedKeepAt, Model.KeepAtList)
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <div align="right">Counterparty  <span class="error">*</span> : </div>
                            </td>
                            <td>&nbsp;</td>
                            <td>@Html.DropDownListFor(x => x.SelectedCounterParty, Model.CounterPartyList)
                                @*<select name="select11" id="select9">
                                    <option>--Select data--</option>
                                    <option value="1">HSBC</option>
                                    <option value="2">BBL</option>
                                    <option value="3">KL</option>
                                </select>*@</td>
                            <td>&nbsp;</td>
                            <td>&nbsp;</td>
                            <td>&nbsp;</td>
                        </tr>
                        <tr>
                            <td>
                                <div align="right">Purchase Value (Local THB)   : </div>
                            </td>
                            <td>&nbsp;</td>
                            <td>

                                @Html.TextBoxFor(model => model.Purchase.PurchaseValueTh, new { @readonly = "readonly",@class = "inputNumberField"  ,@Value = ThaireInvestmentWeb.Util.WebUtil.FormatCurrency2(@Model.Purchase.PurchaseValueTh) })

                                &nbsp;</td>
                            <td>
                                <div align="right"></div>
                            </td>
                            <td>&nbsp;</td>
                            <td>&nbsp;</td>
                        </tr>
                        <tr>
                            <td>
                                <div align="right">Currency   : </div>
                            </td>
                            <td>&nbsp;</td>
                            <td>
                      
                                @Html.DropDownListFor(x => x.SelectedCurrency, Model.CurrencyList)
                                &nbsp;</td>
                            <td>
                                <div align="right">Exch. Rate  : </div>
                            </td>
                            <td>&nbsp;</td>
                            <td>
                                @Html.TextBoxFor(model => model.Purchase.ExchRate, new { @class = "inputNumberField" ,@Value = ThaireInvestmentWeb.Util.WebUtil.FormatCurrency2(@Model.Purchase.ExchRate)  })
                                @Html.ValidationMessageFor(model => model.Purchase.ExchRate)

                            </td>
                        </tr>
                        <tr>
                            <td>
                                <div align="right">Purchase Value (Foreign)  : </div>
                            </td>
                            <td>&nbsp;</td>
                            <td>
                                @Html.TextBoxFor(model => model.Purchase.PurchaseValueForeign, new { @readonly = "readonly",@class = "inputNumberField"  ,@Value = ThaireInvestmentWeb.Util.WebUtil.FormatCurrency2(@Model.Purchase.PurchaseValueForeign) })
                            </td>
                            <td>
                                <div align="right"></div>
                            </td>
                            <td>&nbsp;</td>
                            <td>&nbsp;</td>
                        </tr>

                        <tr>
                            <td>
                                <div align="right">Related / Non Related    : </div>
                            </td>
                            <td>&nbsp;</td>
                            <td>
                 
                                @Html.DropDownListFor(x => x.SelectedRelatedOrNonRelated, Model.RelatedOrNonRelatedList)

                                &nbsp;</td>
                            <td>&nbsp;</td>
                            <td>&nbsp;</td>
                            <td>&nbsp;</td>
                        </tr>
                        <tr>
                            <td>
                                <div align="right">Index Ratio    : </div>
                            </td>
                            <td>&nbsp;</td>
                            <td>
                                @Html.TextBoxFor(model => model.Purchase.IndexRatio)
                                @Html.ValidationMessageFor(model => model.Purchase.IndexRatio)
                                &nbsp;</td>
                            <td>&nbsp;</td>
                            <td>&nbsp;</td>
                            <td>&nbsp;</td>
                        </tr>
                        <tr>
                            <td>
                                <div align="right">Remark (OIC) : </div>
                            </td>
                            <td>&nbsp;</td>
                            <td>
                                @Html.TextBoxFor(model => model.Purchase.RemarkOic)
                                @Html.ValidationMessageFor(model => model.Purchase.RemarkOic)
                            </td>
                           <td>
                                <div align="right">Remain Unit : </div>
                            </td>
                            <td>&nbsp;</td>
                            <td>
                                @Html.TextBoxFor(model => model.Purchase.RemainUnit, new { @readonly = "readonly" ,@class = "inputNumberField" ,@Value = ThaireInvestmentWeb.Util.WebUtil.FormatCurrency0(@Model.Purchase.RemainUnit) })
                              
                            </td>
                        </tr>
                    </table>

                    @Html.HiddenFor(x => x.PurchaseID)
                    @Html.HiddenFor(x => x.HeaderID)

                    <table width="95%" height="85" border="0" align="center">
                        <tr>
                            <td>
                                <div align="center">

                                    <input id="SubmitBtn" type="submit" name="SubmitBtn" value=" Submit " class="button" need-confirm="true">
                                    &nbsp;&nbsp; 
                                    &nbsp;&nbsp; 
                                    <input id="CancelBtn" type="button" name="CancelBtn" value=" Cancel " class="button" >
                                </div>
                            </td>
                        </tr>
                        @{
                                                    if (Model.UpdateMode)
                                                    {
                            <tr>
                                <td>
                                    <div align="center">
                                        <input type="button" name="Submit4" class="btsub" value="Coupon & Amortize" onclick="self.location.href = 'CouponTableAndAmortize?purchaseID=@Model.PurchaseID';">
                                        &nbsp;&nbsp; 
                                    <input  type="button" name="Submit42" class="btsub" value="  Sale  " onclick="self.location.href = 'FixedIncomeSale?purchaseID=@Model.PurchaseID    ';">
                                        &nbsp;&nbsp; 
                                    <input type="button" name="Submit422" class="btsub" value="  Guarantee  " onclick="self.location.href = 'FixedIncomeGuarantee?purchaseID=@Model.PurchaseID    ';">
                                    </div>
                                </td>
                            </tr>
                                                    }
                        }
                    </table>
                    @Html.HiddenFor(x => x.UpdateMode);
                 
                 
                }
               
                <br>
            </td>
        </tr>
    </table>

</p>




